import 'dart:io';

import 'package:flutter/material.dart';
import 'package:furaha_mkopo/commonTool/fm_language_tool.dart';
import 'package:furaha_mkopo/page/authentication/dialog/fm_cupertino_image_picker_sheet.dart';
import 'package:furaha_mkopo/page/authentication/enum/fm_auth_select_enum.dart';
import 'package:furaha_mkopo/page/authentication/enum/fm_authentication_enum.dart';

class FMIdCardFontDialog extends StatelessWidget {
  FMAuthenticationEnum type;
  FMAuthSelectEnum select;
  Function(File? value,FMAuthenticationEnum type,FMAuthSelectEnum select,String alighted) onSelect;
  FMIdCardFontDialog({super.key, required this.type,required this.select, required this.onSelect});

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: (){
        Navigator.of(context).pop();
      },
      child: Scaffold(
        backgroundColor: Colors.transparent,
        body: GestureDetector(
          onTap: (){

          },
          child: Center(
            child: Container(
              width: 311,
              height: 504,
              alignment: Alignment.topCenter,
              decoration: const BoxDecoration(
                image: DecorationImage(
                  image: AssetImage('assets/authentication/ic_id_card_font_dialog_bg.png'),
                  fit: BoxFit.fill,
                ),
              ),
              child: Column(
                children: [
                  const SizedBox(height: 12,),
                  Container(
                    alignment: Alignment.centerLeft,
                    margin: const EdgeInsets.only(left: 12),
                    height: 56,
                    child: Text(
                      getTitle(),
                      style: TextStyle(
                          fontSize: getTitleFontSize(),
                          fontWeight: FontWeight.w700,
                          color: const Color(0xFF333333)),
                    ),
                  ),

                  Container(
                    width: 267,
                    height: 227,
                    margin: const EdgeInsets.only(top: 40,left: 12,right: 12),
                    decoration: BoxDecoration(
                      image: DecorationImage(
                        image: AssetImage(getImagePath()),
                      ),
                    ),
                  ),
                  const SizedBox(height: 30,),
                  GestureDetector(
                    behavior: HitTestBehavior.opaque,
                    onTap: (){
                      String alighted = '';
                      if(type == FMAuthenticationEnum.face){
                        FMCupertinoImagePickerSheet.showImageSourceTakePhoto(context,imageSource: (imageSource){
                          alighted = imageSource;
                        }).then((value){
                          onSelect(value,type,select,alighted);
                          Navigator.of(context).pop();
                        });
                      }else{
                        FMCupertinoImagePickerSheet.showImageSourceSelector(context,imageSource: (imageSource){
                          alighted = imageSource;
                        }).then((value){
                          onSelect(value,type,select,alighted);
                          Navigator.of(context).pop();
                        });
                      }
                    },
                    child: Container(
                      margin: const EdgeInsets.only(top: 40, left: 20, right: 20),
                      height: 47,
                      width: double.infinity,
                      alignment: Alignment.center,
                      decoration: const BoxDecoration(
                        color: Color(0xFF000000),
                        borderRadius: BorderRadius.all(Radius.circular(8)),
                        image: DecorationImage(
                          image: AssetImage('assets/address/ic_address_arrow.png'),
                        ),
                      ),
                      child: Text(
                        FMLanguageTool.getText('Next'),
                        style: const TextStyle(
                          color: Colors.white,
                          fontSize: 18,
                          fontWeight: FontWeight.w700,
                        ),
                      ),
                    ),
                  ),
                  GestureDetector(
                    behavior: HitTestBehavior.opaque,
                    onTap: (){
                      Navigator.of(context).pop();
                    },
                    child: Container(
                      margin: const EdgeInsets.only(top: 10),
                      alignment: Alignment.center,
                      child: Text(
                        FMLanguageTool.getText("Cancel"),
                        style: const TextStyle(
                          color: Color(0xFF333333),
                          fontSize: 16,
                        ),
                      ),
                    ),
                  )
                ],
              ),
            ),
          ),
        ),
      ),
    );
  }

  String getImagePath(){
    switch(type){
      case FMAuthenticationEnum.idCardFont:
        if(select == FMAuthSelectEnum.nida){
          return FMLanguageTool.getAssets("assets/authentication/ic_id_card_nida_dialog",suffix: ".webp");
        }else if(select == FMAuthSelectEnum.voter){
          return FMLanguageTool.getAssets("assets/authentication/ic_id_card_voter_dialog",suffix: ".webp");
        }else {
          return FMLanguageTool.getAssets("assets/authentication/ic_id_card_font_dialog");
        }
      case FMAuthenticationEnum.idCardBack:
        return 'assets/authentication/ic_id_card_back_dialog.png';
      default:
        return FMLanguageTool.getAssets("assets/authentication/ic_id_card_face_dialog");
    }
  }

  String getTitle(){
    switch(type){
      case FMAuthenticationEnum.idCardFont:
        if(select == FMAuthSelectEnum.nida){
          return 'NIDA sahihi\n  ';
        }else if(select == FMAuthSelectEnum.voter){
          return 'Correct Voter Card\n  ';
        }else {
          return 'Correct\nDemonstration';
        }
      default:
        return 'Correct\nDemonstration';
    }
  }

  double getTitleFontSize(){
    switch(type){
      case FMAuthenticationEnum.idCardFont:
        if(select == FMAuthSelectEnum.nida){
          return 24;
        }else if(select == FMAuthSelectEnum.voter){
          return 18;
        }else {
          return 24;
        }
      default:
        return 24;
    }
  }
}
